<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Eshop - Ecommerce website</title>
    
    <!-- === CSS === -->
    <link rel="stylesheet" href="bootstrap-4.0.0-beta/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/ionicons.css">
    <link rel="stylesheet" href="css/now-ui-kit.css">
    <link rel="stylesheet" href="css/app.css">

</head>
<body onload="doSearch();check()">
<!--=== navbar ===-->
<header class="header">
    <nav class="navbar navbar-expand-sm">
        <div class="container">
            <a class="navbar-brand" href="index.html">EShop</a>
            <button class="navbar-toggler navbar-toggler" type="button" data-toggle="collapse" data-target="#example-navbar" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-bar bar1"></span>
                <span class="navbar-toggler-bar bar2"></span>
                <span class="navbar-toggler-bar bar3"></span>
            </button>
            <div class="collapse navbar-collapse" id="example-navbar" data-nav-image="assets/img/blurred-image-1.jpg">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="index.html">首页</a>
                    </li>
                    <li class="nav-item active dropdown">
                        <a class="nav-link dropdown-toggle" href="http://localhost" id="navbarDropdownMenuLink1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">商城</a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                            <a class="dropdown-item" href="books.html">纸质书</a>
                            <a class="dropdown-item" href="book.html">电子书</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">用户</a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                            <a class="dropdown-item" onclick="check()" href="#" id="login">登陆</a>
                            <a class="dropdown-item" href="cart.html" id="cart">购物车</a>
                            <a class="dropdown-item" href="order.html" id="order">订单管理</a>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</header>
    <!--=== single blog post ===-->
    <section class="blog-post single-post">
        <div class="container">
            <div class="row">
                <div class="col-lg-10 col-md-12-12 col-sm-12 mx-auto">
                    <div class="post post-card">
                        <div class="single-post-header">
                            <div>出版时间</div>
                            <div class="post-tag" id="releaseTime"></div>
                            <ul class="list-inline blog-item-links">
                                <li class="list-inline-item"><a id="addToCart" href="cart.html" onclick="addToCart()">加入购物车</a></li>
                            </ul>
                            <h1 id="nameAndauthor"></h1>
                        </div>
                        <a href="Blog Post Image" class="post-image" ><img src="images/shade.jpg" alt="#" class="img-fluid featured-img"></a>
                        <div class="row">
                            <div class="col-12">
                                <div class="card-details">
                                    <h2>书本简介</h2>
                                    <p id="intro"><p>
                                    <h2>作者简介</h2>
                                    <p id="aboutAuthor"></p>
                                    <h2>价格</h2>
                                    <p id="price"></p>
                                    <h2>评分</h2>
                                    <p id="rate"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!--=== footer ===-->
    <section class="footer">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="footer-wrap text-center">
                        <div class="footer-tag">All rights Reserved EwenTsai</div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script type="text/javascript">
        function doSearch() {
            var arr = getRequest();
            var id = arr['id'];
            //获取dom对象
            var nameAndauthor = document.getElementById("nameAndauthor");
            var releaseTime = document.getElementById("releaseTime");
            var aboutAuthor = document.getElementById("aboutAuthor");
            var intro = document.getElementById("intro");
            var price = document.getElementById("price");
            var rate =document.getElementById("rate");
            //创建ajax对象
            var ajax;
            if (window.XMLHttpRequest)
            {
                //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
                ajax=new XMLHttpRequest();
            }
            else
            {
                // IE6, IE5 浏览器执行代码
                ajax=new ActiveXObject("Microsoft.XMLHTTP");
            }

            ajax.onreadystatechange = function () {
                if(ajax.readyState===4 && ajax.status===200){
                    var jsonObj = eval('('+ajax.responseText+')');

                    releaseTime.innerHTML = jsonObj.releaseTime;
                    nameAndauthor.innerHTML = jsonObj.bookname+" -- "+jsonObj.author;
                    aboutAuthor.innerHTML = jsonObj.aboutAuthor;
                    intro.innerHTML = jsonObj.intro;
                    price.innerHTML = jsonObj.price;
                    rate.innerHTML = jsonObj.rate;
                }
            }
            ajax.open("get","/BTS/searchBook.do?id="+id);
            ajax.send(null);
        }
    </script>
    <script type="text/javascript">
        function addToCart() {
            var arr = getRequest();
            var id = arr['id'];

            //创建ajax对象
            var ajax;
            if (window.XMLHttpRequest)
            {
                //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
                ajax=new XMLHttpRequest();
            }
            else
            {
                // IE6, IE5 浏览器执行代码
                ajax=new ActiveXObject("Microsoft.XMLHTTP");
            }

            ajax.onreadystatechange = function () {}
            ajax.open("get","/BTS/cart.do?id="+id);
            ajax.send(null);
        }
    </script>

    <!-- ==== js ==== -->
    <script src="js/jquery-3.2.1.slim.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="bootstrap-4.0.0-beta/js/bootstrap.min.js"></script>
    <script src="js/app.js"></script>
    <script src="js/util.js"></script>
</body>
</html>